package com.example.yaja.yaja.service;

import com.example.yaja.yaja.dao.UserMapper;
import com.example.yaja.yaja.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Zero on 2017/12/4.
 */
@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    /**
     * 通过名字查找用户
     * @param username
     * @return
     */
    @Override
    public User findUserByUsername(String username) {
        return userMapper.selectByUsername(username);
    }

    /**
     * 添加用户
     * @param user
     * @return
     */
    @Override
    public int addUser(User user) {
        return userMapper.insertSelective(user);
    }

    /**
     * 通过userId获取用户信息
     * @param userId
     * @return
     */
    @Override
    public User findUserById(Integer userId) {
        return userMapper.selectByPrimaryKey(userId);
    }

    /**
     * 更新用户状态
     * @param userId
     * @param state
     * @return
     */
    @Override
    public int updateUserState(Integer userId, Integer state) {
        Map<String,Object> params=new HashMap<String,Object>();
        params.put("state",state);
        params.put("userId",userId);
        return userMapper.updateUserState(params);
    }
}
